{if $DT_PC}
{template 'header'}
{else}
{template 'header', 'member'}
{/if}
{if $action == 'show'}
<div class="m">
	<div class="nav">
		<a href="{$MODULE[1][linkurl]}">首页</a> <i>&gt;</i> <a href="{$MOD[linkurl]}">{$MOD[name]}</a> <i>&gt;</i> 提交订单
	</div>
	<div class="cart-msg"><img src="image/ok.gif" alt="" align="absmiddle"/>  订单提交成功！ 
	&nbsp;&nbsp;&nbsp;&nbsp;<a href="{$forward}" class="b">支付订单</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="{$MOD[linkurl]}" class="b">继续购物</a></div>
	<meta http-equiv="refresh" content="5;URL={$forward}"/>
</div>
{else}
<script type="text/javascript">var errimg = '{DT_SKIN}image/nopic50.gif';</script>
<div class="m">
	<div class="nav">
		<a href="{$MODULE[1][linkurl]}">首页</a> <i>&gt;</i> <a href="{$MOD[linkurl]}">{$MOD[name]}</a> <i>&gt;</i> 提交订单
	</div>
	{if $lists}
	<form method="post" action="buy.php" onsubmit="return check();">
	<input type="hidden" name="submit" value="1"/>
	<input type="hidden" name="mid" value="{$mid}"/>
	<div class="b20 bd-t"></div>
	<div>
		<div class="f_r" style="padding:10px 0 0 0;"><a href="cart.php?mid={$mid}" class="b">返回购物车重新挑选</a></div>
		<img src="{DT_SKIN}image/buy_1.gif" width="160" height="30" alt=""/> 
	</div>
	<div class="b20"></div>

	<table cellpadding="16" cellspacing="0" class="tb">
	<tr>
	<th width="50">图片</th>
	<th>商品</th>
	<th width="60">库存</th>
	<th width="60">单价</th>
	<th width="100">数量</th>
	<th width="90">快递</th>
	<th width="80">运费</th>
	<th width="100">小计</th>
	</tr>
	{loop $lists $tags}
	{loop $tags $i $t}
	{if $i == 0}
	<tr bgcolor="#FAFAFA" align="center">
	<td>卖家</td>
	<td align="left">
	{if $t[vip]}<img src="{DT_SKIN}image/vip_{$t[vip]}.gif" alt="{VIP}" title="{VIP}:{$t[vip]}级" align="absmiddle"/> {/if}<a href="{userurl($t[username])}" target="_blank">{$t[company]}</a>
	{if $DT[im_web]}{im_web($t[username].'&mid='.$t[mid].'&itemid='.$t[itemid])}&nbsp;{/if}
	{if $t[qq] && $DT[im_qq]}{im_qq($t[qq])}&nbsp;{/if}
	{if $t[wx] && $DT[im_wx]}{im_wx($t[wx], $t[username])}&nbsp;{/if}
	{if $t[ali] && $DT[im_ali]}{im_ali($t[ali])}&nbsp;{/if}
	{if $t[skype] && $DT[im_skype]}{im_skype($t[skype])}</a>&nbsp;{/if}
	</td>
	<td></td>
	{php $promos = get_promos($t[username]);}
	{php $coupons = get_coupons($_username, $t[username]);}	
	<td>{if $promos}<a href="{$MODULE[2][linkurl]}coupon.php?username={$t[username]}" class="b" target="_blank"><div class="cart-promo">领券</div></a>{/if}</td>
	<td colspan="3" align="left">
	{if $coupons}
	<select name="coupon[{$t[username]}]" id="coupon-{$t[username]}" onchange="calculate();">
	<option value="0">我的优惠券</option>
	{loop $coupons $c}
	<option value="{$c[itemid]}" coupon-price="{$c[price]}" coupon-cost="{$c[cost]}">{$DT[money_sign]}{$c[price]}{if $c[cost]}，满{$c[cost]}可用{/if}</option>
	{/loop}
	</select>	
	{/if}	
	</td>
	<td><span class="f_price px16" id="total-{$t[username]}" data-user="{$t[username]}">0.00</span></td>
	</td>
	</tr>
	{/if}
	<tr align="center" data-key="{$t[key]}">
	<td><a href="{$t[linkurl]}" target="_blank"><img src="{$t[thumb]}" width="50" alt="{$t[alt]}" onerror="this.src=errimg;"/></a></td>
	<td align="left" style="line-height:24px;color:#666666;">
	<a href="{$t[linkurl]}" target="_blank" class="b" title="{$t[alt]}">{$t[title]}</a><br/>
	<div style="padding:3px 0 3px 0;">备注：<input type="text" name="post[{$t[key]}][note]" value="" size="20" style="border:#CCCCCC 1px solid;" maxlength="100" title="限100字以内"/></div>
	品牌:{if $t[brand]}{$t[brand]}{else}未填写{/if}&nbsp;{if $t[m1]}{$t[n1]}:{$t[m1]}&nbsp;{/if}{if $t[m2]}{$t[n2]}:{$t[m2]}&nbsp;{/if}{if $t[m3]}{$t[n3]}:{$t[m3]}&nbsp;{/if}
	</td>
	<td>{$t[amount]}</td>
	<td title="{if $t[a2]}{$t[a1]}-{$t[a2]}{$t[unit]} {$DT[money_sign]}{$t[p1]}&#10;{if $t[a3]}{$t[a2]+1}-{$t[a3]}{$t[unit]} {$DT[money_sign]}{$t[p2]}&#10;{$t[a3]}{$t[unit]}以上 {$DT[money_sign]}{$t[p3]}{else}{$t[a2]+1}{$t[unit]}以上 {$DT[money_sign]}{$t[p2]}{/if}{else}{$DT[money_sign]}{$t[p1]}{/if}"><span class="f_b" id="price_{$t[key]}">{$t[price]}</span></td>
	<td><img src="{DT_SKIN}image/arrow_l.gif" width="16" height="8" alt="减少" class="c_p" onclick="alter('{$t[key]}', '-');"/> <input type="text" name="post[{$t[key]}][number]" value="{$t[a]}" size="3" class="cc_inp" id="number_{$t[key]}" onblur="calculate();"/> <img src="{DT_SKIN}image/arrow_r.gif" width="16" height="8" alt="增加" class="c_p" onclick="alter('{$t[key]}', '+');"/></td>
	<td>
	<select name="post[{$t[key]}][express]" id="express_{$t[key]}" onchange="calculate();">
	{if $t[express_name_1] == '包邮'}
		{if $t[fee_start_1]>0}
		{if $t[fee_start_2]>0}<option value="2" data-2>{$t[express_name_2]}</option>{/if}
		{if $t[fee_start_3]>0}<option value="3" data-3>{$t[express_name_3]}</option>{/if}
		<option value="-1" data--1>包邮</option>
		{if $t[fee_start_2]>0 || $t[fee_start_3]>0}
		{else}
		<option value="0" data-0>联系卖家</option>
		{/if}
		{else}
		<option value="0" data-0>包邮</option>
		{/if}
	{elseif $t[fee_start_1]>0 || $t[fee_start_2]>0 || $t[fee_start_3]>0}
		{if $t[fee_start_1]>0}<option value="1">{$t[express_name_1]}</option>{/if}
		{if $t[fee_start_2]>0}<option value="2">{$t[express_name_2]}</option>{/if}
		{if $t[fee_start_3]>0}<option value="3">{$t[express_name_3]}</option>{/if}
	{else}
	<option value="0">联系卖家</option>
	{/if}
	</select>
	{if $t[express_name_1] == '包邮' && $t[fee_start_1]>0}
	<div style="margin-top:16px;" class="f_gray">满{$t[fee_start_1]}包邮</div>
	{/if}
	{if $t[cod]}
	<div style="margin-top:16px;"><input type="checkbox" name="post[{$t[key]}][cod]" value="1" checked{if $t[cod] == 1} disabled{/if}/> 货到付款</div>
	{/if}
	<input type="hidden" id="a1_{$t[key]}" value="{$t[a1]}"/>
	<input type="hidden" id="a2_{$t[key]}" value="{$t[a2]}"/>
	<input type="hidden" id="a3_{$t[key]}" value="{$t[a3]}"/>
	<input type="hidden" id="p1_{$t[key]}" value="{$t[p1]}"/>
	<input type="hidden" id="p2_{$t[key]}" value="{$t[p2]}"/>
	<input type="hidden" id="p3_{$t[key]}" value="{$t[p3]}"/>
	<input type="hidden" id="amount_{$t[key]}" value="{$t[amount]}"/>
	<input type="hidden" id="fee_start_{$t[key]}_1" value="{$t[fee_start_1]}"/>
	<input type="hidden" id="fee_step_{$t[key]}_1" value="{$t[fee_step_1]}"/>
	<input type="hidden" id="fee_start_{$t[key]}_2" value="{$t[fee_start_2]}"/>
	<input type="hidden" id="fee_step_{$t[key]}_2" value="{$t[fee_step_2]}"/>
	<input type="hidden" id="fee_start_{$t[key]}_3" value="{$t[fee_start_3]}"/>
	<input type="hidden" id="fee_step_{$t[key]}_3" value="{$t[fee_step_3]}"/>
	</td>
	<td><span class="f_price" id="fee_{$t[key]}">0.00</span></td>
	<td><span class="f_price" id="total_{$t[key]}" total-{$t[username]}="1">0.00</span></td>
	</tr>
	{/loop}
	{/loop}
	</table>
	<div class="b20"></div>
	<table cellpadding="10" cellspacing="0" width="100%">
	<tr>
	<td class="f_gray">提示：实际的运费可能因为收货地址的不同而有差异，具体以提交之后系统计算或与卖家协商为准</td>
	<td class="t_r" width="300">共 <span class="f_red" id="total_good">{$num}</span> 种商品，总价：</td>
	<td class="t_r" width="100"><span id="total_price"></span></td>
	<td width="10"></td>
	</tr>
	<tr>
	<td></td>
	<td class="t_r">优惠：</td>
	<td class="t_r"><span id="total_discount"></span></td>
	<td></td>
	</tr>
	<tr>
	<td></td>
	<td class="t_r">实付：</td>
	<td class="t_r"><span class="f_red f_b px16" id="total_amount"></span></td>
	<td></td>
	</tr>
	</table>
	<div class="b20"></div>
	<div><img src="{DT_SKIN}image/buy_2.gif" width="160" height="30" alt=""/></div>
	<div class="b20"></div>

	<table cellpadding="16" cellspacing="0" class="tf">
	<tr>
	<td class="tl"><span class="f_red">&nbsp;</span> 常用地址：</td>
	<td>
	{if $address}
		{loop $address $k $v}
		<div>
		{if $k == 0}<span class="f_r"><a href="{$MODULE[2][linkurl]}address.php?action=add" class="b" target="_blank">新增地址</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="{$MODULE[2][linkurl]}address.php" class="b" target="_blank">管理地址</a></span>{/if}
		<input type="radio" name="addr" id="addr_{$k}" value="{$v[areaid]}|{$v[street]}|{$v[postcode]}|{$v[truename]}|{$v[mobile]}" onclick="Adr(this.value);"{if $k == 0} checked{/if}/><label for="addr_{$k}"> {$v[address]} ({$v[truename]}) {$v[mobile]}</label></div>
		<div class="b10"></div>
		{/loop}
	{else}
		<strong>暂无常用收货地址</strong>&nbsp;&nbsp;&nbsp;&nbsp;<a href="{$MODULE[2][linkurl]}address.php?action=add" class="b" target="_blank">新增地址</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="{$MODULE[2][linkurl]}address.php" class="b" target="_blank">管理地址</a>
	{/if}
	</td>
	</tr>
	<tr>
	<td class="tl"><span class="f_red">*</span> 收货地址：</td>
	<td>{ajax_area_select('add[areaid]', '请选择', $user[areaid])} <input type="text" size="60" name="add[address]" id="address" value="{$user[address]}"/> <span id="dareaid" class="f_red"></span><span id="daddress" class="f_red"></span></td>
	</tr>
	<tr>
	<td class="tl"><span class="f_red">*</span> 邮政编码：</td>
	<td><input type="text" size="10" name="add[postcode]" id="postcode" value="{$user[postcode]}"/> <span id="dpostcode" class="f_red"></span></td>
	</tr>
	<tr>
	<td class="tl"><span class="f_red">*</span> 真实姓名：</td>
	<td><input type="text" size="10" name="add[truename]" id="truename" value="{$user[truename]}"/> <span id="dtruename" class="f_red"></span></td>
	</tr>
	<tr>
	<td class="tl"><span class="f_red">*</span> 手机号码：</td>
	<td><input type="text" size="20" name="add[mobile]" id="mobile" value="{$user[mobile]}"/> <span id="dmobile" class="f_red"></span></td>
	</tr>
	<tr>
	<td class="tl"> </td>
	<td><input type="submit" name="submit" value=" 立即购买 " class="btn-green"/></td>
	</tr>
	</table>

	</form>
	{else}
		<div class="cart-msg">您还没有挑选商品，赶快行动吧！马上去 <a href="{$MOD[linkurl]}" class="b">挑选商品</a></div>
	{/if}
</div>
{/if}
{if !$_userid}<script type="text/javascript" src="{DT_STATIC}file/script/guest.js"></script>{/if}
<script type="text/javascript">
function check() {
	if(Dd('total_amount').innerHTML == '0.00') {
		alert('订单总额为0.00，请检查商品数量');
		window.scroll(0, 0);
		return false;
	}
	var l;
	var f;
	f = 'areaid_1';
	if(Dd(f).value == 0) {
		Dmsg('请选择所在地区', 'areaid', 1);
		return false;
	}
	f = 'address';
	l = Dd(f).value.length;
	if(l < 5) {
		Dmsg('请填写街道地址', f);
		return false;
	}
	f = 'postcode';
	l = Dd(f).value.length;
	if(l < 6) {
		Dmsg('请填写邮政编码', f);
		return false;
	}
	f = 'truename';
	l = Dd(f).value.length;
	if(l < 2) {
		Dmsg('请填写真实姓名', f);
		return false;
	}
	f = 'mobile';
	l = Dd(f).value.length;
	if(l < 11) {
		Dmsg('请填写手机号码', f);
		return false;
	}
	return true;
}
function Adr(s) {
	var t = s.split('|');
	try {
		Dd('address').value = t[1];
		Dd('postcode').value = t[2];
		Dd('truename').value = t[3];
		Dd('mobile').value = t[4];
		load_area(t[0], 1);
	}
	catch (e) {}
}
{if $address}Adr(Dd('addr_0').value);{/if}
function alter(i, t) {
	if(t == '+') {
		var maxa = parseFloat(Dd('amount_'+i).value);
		if(maxa && Dd('number_'+i).value >= maxa) return;
		Dd('number_'+i).value =  parseInt(Dd('number_'+i).value) + 1;
	} else {
		var mina = parseFloat(Dd('a1_'+i).value);
		if(Dd('number_'+i).value <= mina) return;
		Dd('number_'+i).value = parseInt(Dd('number_'+i).value) - 1;
	}
	calculate();
}
function get_price(i) {
	if(Dd('a2_'+i).value > 0) {
		if(Dd('a3_'+i).value > 1 && parseInt(Dd('number_'+i).value) > parseInt(Dd('a3_'+i).value)) return Dd('p3_'+i).value;
		if(Dd('a2_'+i).value > 1 && parseInt(Dd('number_'+i).value) > parseInt(Dd('a2_'+i).value)) return Dd('p2_'+i).value;
	}
	return Dd('p1_'+i).value
}
function calculate() {
	var _good = 0;
	$('[data-key]').each(function() {
		var num, good, maxa, mina, price;
		var key = $(this).attr('data-key');
		num = parseInt(Dd('number_'+key).value);
		maxa = parseInt(Dd('amount_'+key).value);
		mina = parseInt(Dd('a1_'+key).value);
		if(num < mina) Dd('number_'+key).value = num = mina;
		if(num > maxa) Dd('number_'+key).value = num = maxa;
		if(isNaN(num) || num < 0) Dd('number_'+key).value = num = mina;
		price = parseFloat(get_price(key));
		good = price*num;
		var es = $('#express_'+key).html();
		if(es.indexOf('data--1') != -1) {
			if(good >= parseFloat(Dd('fee_start_'+key+'_1').value)) {
				$('#express_'+key).val('-1');
			} else {
				if(es.indexOf('data-0') != -1) {
					$('#express_'+key).val('0');
				} else if(es.indexOf('data-2') != -1) {
					$('#express_'+key).val('2');
				} else if(es.indexOf('data-3') != -1) {
					$('#express_'+key).val('3');
				}
			}
		} 
		if(Dd('express_'+key).value > 0) {
			var fee = parseFloat(Dd('fee_start_'+key+'_'+Dd('express_'+key).value).value) + parseFloat(Dd('fee_step_'+key+'_'+Dd('express_'+key).value).value)*(num-1);
			Dd('fee_'+key).innerHTML = fee.toFixed(2);
			Dd('total_'+key).innerHTML = (good+fee).toFixed(2);
			_good += fee;
		} else {
			Dd('fee_'+key).innerHTML = '0.00';
			Dd('total_'+key).innerHTML = good.toFixed(2);
		}
		Dd('price_'+key).innerHTML = price.toFixed(2);
		_good += good;
	});
	var d_c = 0;
	var t_a = _good;
	$('[data-user]').each(function() {
		var user = $(this).attr('data-user');
		var t_t = 0;
		$('[total-'+user+']').each(function() {
			t_t += parseFloat($(this).html());
		});
		if($('#coupon-'+user).val() > 0) {
			var c_c = parseFloat($('#coupon-'+user+' :selected').attr('coupon-cost'));
			var c_p = parseFloat($('#coupon-'+user+' :selected').attr('coupon-price'));
			if(c_c) {
				if(c_c <= t_t) {
					t_t = t_t - c_p;
					t_a = t_a - c_p;
					d_c += c_p;
				} else {
					$('#coupon-'+user).val('0');
				}
			} else {
				t_t = t_t - c_p;
				t_a = t_a - c_p;
				d_c += c_p;
			}
		}
		$(this).html(t_t.toFixed(2));
	});
	$('#total_price').html(_good.toFixed(2));
	$('#total_discount').html(d_c > 0 ? '-'+d_c.toFixed(2) : '0.00');
	$('#total_amount').html(t_a.toFixed(2));
}
{if $lists}
$(function(){calculate();});
{/if}
</script>
{if $DT_PC}
{template 'footer'}
{else}
{template 'footer', 'member'}
{/if}